﻿using System;
using System.Collections.Generic;
using System.Linq;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using OrkutAPILibrary.Constants;
using OrkutAPILibrary.Entities;
using OrkutAPILibrary.Enums;
using OrkutAPILibrary.Methods;

namespace OrkutAPILibrary
{
    /// <summary>
    /// Orkut Library which provides a wrapper around Orkut methods
    /// </summary>
    public class OrkutLibrary
    {
        #region Private Variables
        bool _isAuthorizationNeeded = true;
        static OrkutLibrary _clientLibrary;
        static string _orkutAccessToken;
        private static ApplicationEnvironment _appEnv;
        static IConsumerTokenManager _orkutLibTokenManager;
        static ConsumerBase _orkut;
        static string _requestToken;
        private static readonly MessageReceivingEndpoint GetOrkutEndpoint = new MessageReceivingEndpoint("http://www.orkut.com/social/rpc", HttpDeliveryMethods.GetRequest);
        #endregion

        #region Methods Used For Orkut Request
        /// <summary>
        /// Initializes a new instance of the <see cref="OrkutLibrary"/> class.
        /// </summary>
        private OrkutLibrary()
        {

        }

        /// <summary>
        /// Gets or sets a value indicating whether authorization is needed for this instance.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if authorization is needed for this instance; otherwise, <c>false</c>.
        /// </value>
        public bool IsAuthorizationNeeded
        {
            get
            {
                if (!String.IsNullOrEmpty(_orkutAccessToken))
                    _isAuthorizationNeeded = false;
                return _isAuthorizationNeeded;
            }
            private set
            {
                _isAuthorizationNeeded = value;
            }
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="appEnv">The application environment.</param>
        /// <param name="tokenManager">The token manager.</param>
        /// <param name="orkutAccessToken">The orkut access token.</param>
        /// <returns></returns>
        public static OrkutLibrary Initialize(ApplicationEnvironment appEnv, IConsumerTokenManager tokenManager, string orkutAccessToken = null)
        {
            if (_clientLibrary == null)
                _clientLibrary = new OrkutLibrary();

            _orkutLibTokenManager = tokenManager;
            _appEnv = appEnv;

            switch (_appEnv)
            {
                case ApplicationEnvironment.Desktop:
                    _orkut = new DesktopConsumer(OrkutConsumer.ServiceDescription, _orkutLibTokenManager);
                    break;
                case ApplicationEnvironment.Web:
                    _orkut = new WebConsumer(OrkutConsumer.ServiceDescription, _orkutLibTokenManager);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("appEnv");
            }

            _orkutAccessToken = orkutAccessToken;

            return _clientLibrary;
        }

        /// <summary>
        /// Gets the URL for authorization.
        /// </summary>
        /// <exception cref="OrkutException">Orkut Exception</exception>
        /// <returns></returns>
        public Uri GetUrlForAuthorization()
        {
            if (_orkutLibTokenManager == null)
            {
                throw new OrkutException("The Token Manager class is not initialized") { IsClientError = true };
            }

            if (_appEnv == ApplicationEnvironment.Web)
            {
                throw new OrkutException("This method is only used for Desktop environments.") { IsClientError = true };
            }

            if (IsAuthorizationNeeded)
            {
                var authUrl = OrkutConsumer.RequestAuthorization((DesktopConsumer)_orkut, out _requestToken);
                return authUrl;
            }
            throw new OrkutException("Authorization is not needed as we already have the Orkut Access Token") { IsClientError = true };
        }

        /// <summary>
        /// Authorizes the specified verifier code.
        /// </summary>
        /// <param name="verifierCode">The verifier code.</param>
        /// <exception cref="OrkutException">Orkut Exception</exception>
        /// <returns></returns>
        public void Authorize(string verifierCode)
        {
            if (_orkutLibTokenManager == null)
            {
                throw new OrkutException("The Token Manager class is not initialized") { IsClientError = true };
            }

            if (_appEnv == ApplicationEnvironment.Web)
            {
                throw new OrkutException("This method is only used for Desktop environments.") { IsClientError = true };
            }

            if (string.IsNullOrEmpty(verifierCode.Trim()))
            {
                throw new OrkutException("Verifier code cannot be null or empty") { IsClientError = true };
            }

            if (!IsAuthorizationNeeded)
            {
                throw new OrkutException("Authorization is not needed as we already have the Orkut Access Token") { IsClientError = true };
            }

            _orkutAccessToken = ((DesktopConsumer)_orkut).ProcessUserAuthorization(_requestToken, verifierCode).AccessToken;
        }

        /// <summary>
        /// Authorizes the web request.
        /// </summary>
        public void AuthorizeWebRequest()
        {
            if (_orkutLibTokenManager == null)
            {
                throw new OrkutException("The Token Manager class is not initialized") { IsClientError = true };
            }

            if (_appEnv == ApplicationEnvironment.Desktop)
            {
                throw new OrkutException("This method is only used for Web environments.") { IsClientError = true };
            }

            if (!IsAuthorizationNeeded)
            {
                throw new OrkutException("Authorization is not needed as we already have the Orkut Access Token") { IsClientError = true };
            }

            var accessTokenResponse = ((WebConsumer)_orkut).ProcessUserAuthorization();
            if (accessTokenResponse != null)
            {
                _orkutAccessToken = accessTokenResponse.AccessToken;
            }
            else
            {
                OrkutConsumer.RequestAuthorization((WebConsumer)_orkut);
            }
        }

        /// <summary>
        /// Checks for authorization.
        /// </summary>
        private void CheckForAuthorization()
        {
            if (IsAuthorizationNeeded)
            {
                throw new OrkutException("Please authorize the OrkutLibrary first!") { IsClientError = true };
            }
        }

        /// <summary>
        /// Executes the request.
        /// </summary>
        /// <param name="requestData">The request data.</param>
        /// <returns></returns>
        internal static string ExecuteRequest(IDictionary<string, string> requestData)
        {
            if (requestData == null)
                throw new ArgumentNullException("requestData");

            if (_orkut == null)
                throw new OrkutException("Orkut Consumer is null!");

            var request = _orkut.PrepareAuthorizedRequest(GetOrkutEndpoint, _orkutAccessToken, requestData);

            if (request == null) return string.Empty;

            string body;
            using (var response = _orkut.Channel.WebRequestHandler.GetResponse(request))
            {
                body = response.GetResponseReader().ReadToEnd();
            }

            body = body.Replace("{\"data\":", "");
            return body.Remove(body.Count() - 2, 1);
        }
        #endregion

        #region OrkutProfileFactory
        /// <summary>
        /// Gets the self profile.
        /// </summary>
        /// <exception cref="OrkutException">Orkut Exception</exception>
        /// <returns></returns>
        public OrkutPerson GetSelfProfile()
        {
            CheckForAuthorization();

            return OrkutProfileFactory.GetSelfProfile();
        }

        /// <summary>
        /// Gets the profile of user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public OrkutPerson GetProfileOfUser(string userId)
        {
            CheckForAuthorization();

            return OrkutProfileFactory.GetProfileOfUser(userId);
        }

        /// <summary>
        /// Updates the self profile.
        /// </summary>
        /// <param name="profileToUpdate">The profile to update.</param>
        /// <returns></returns>
        public bool UpdateSelfProfile(OrkutPerson profileToUpdate)
        {
            CheckForAuthorization();

            return OrkutProfileFactory.UpdateSelfProfile(profileToUpdate);
        }
        #endregion

        #region OrkutActivityFactory
        /// <summary>
        /// Gets the self activities.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutActivity> GetSelfActivities(int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfActivities)
        {
            CheckForAuthorization();

            return OrkutActivityFactory.GetSelfActivities(startIndex, count);
        }

        /// <summary>
        /// Gets the activities of user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutActivity> GetActivitiesOfUser(string userId, int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfActivities)
        {
            CheckForAuthorization();

            return OrkutActivityFactory.GetActivitiesOfUser(userId, startIndex, count);
        }

        /// <summary>
        /// Posts the activity.
        /// </summary>
        /// <param name="activityTitle">The activity title.</param>
        /// <param name="activityBody">The activity body.</param>
        /// <returns></returns>
        public bool PostActivity(string activityTitle, string activityBody)
        {
            CheckForAuthorization();

            return OrkutActivityFactory.PostActivity(activityTitle, activityBody);
        }
        #endregion

        #region OrkutAlbumFactory
        /// <summary>
        /// Gets the self albums.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutAlbum> GetSelfAlbums(int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfAlbums)
        {
            CheckForAuthorization();

            return OrkutAlbumFactory.GetSelfAlbums(startIndex, count);
        }

        /// <summary>
        /// Gets the albums.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutAlbum> GetAlbums(string userId, int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfAlbums)
        {
            CheckForAuthorization();

            return OrkutAlbumFactory.GetAlbums(userId, startIndex, count);
        }

        /// <summary>
        /// Updates the album.
        /// </summary>
        /// <param name="albumToUpdate">The album to update.</param>
        /// <returns></returns>
        public bool UpdateAlbum(OrkutAlbum albumToUpdate)
        {
            CheckForAuthorization();

            return OrkutAlbumFactory.UpdateAlbum(albumToUpdate);
        }

        /// <summary>
        /// Creates the album.
        /// </summary>
        /// <param name="albumTitle">The album title.</param>
        /// <param name="albumDescription">The album description.</param>
        /// <returns></returns>
        public OrkutAlbum CreateAlbum(string albumTitle, string albumDescription)
        {
            CheckForAuthorization();

            return OrkutAlbumFactory.CreateAlbum(albumTitle, albumDescription);
        }

        /// <summary>
        /// Deletes the album.
        /// </summary>
        /// <param name="albumId">The album id.</param>
        /// <returns></returns>
        public bool DeleteAlbum(string albumId)
        {
            CheckForAuthorization();

            return OrkutAlbumFactory.DeleteAlbum(albumId);
        }
        #endregion

        #region OrkutCommentFactory
        /// <summary>
        /// Gets the photo comments.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="albumId">The album id.</param>
        /// <param name="photoId">The photo id.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutComment> GetPhotoComments(string userId, string albumId, string photoId, int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfPictureComments)
        {
            CheckForAuthorization();

            return OrkutCommentFactory.GetPhotoComments(userId, albumId, photoId, startIndex, count);
        }

        /// <summary>
        /// Writes the photo comment.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="albumId">The album id.</param>
        /// <param name="photoId">The photo id.</param>
        /// <param name="commentBody">The comment body.</param>
        /// <returns></returns>
        public OrkutComment WritePhotoComment(string userId, string albumId, string photoId, string commentBody)
        {
            CheckForAuthorization();

            return OrkutCommentFactory.WritePhotoComment(userId, albumId, photoId, commentBody);
        }

        /// <summary>
        /// Deletes the photo comment.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="albumId">The album id.</param>
        /// <param name="photoId">The photo id.</param>
        /// <param name="commentId">The comment id.</param>
        /// <returns></returns>
        public bool DeletePhotoComment(string userId, string albumId, string photoId, string commentId)
        {
            CheckForAuthorization();

            return OrkutCommentFactory.DeletePhotoComment(userId, albumId, photoId, commentId);
        }
        #endregion

        #region OrkutFriendFactory
        /// <summary>
        /// Gets the self friends.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutPerson> GetSelfFriends(int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfFriends)
        {
            CheckForAuthorization();

            return OrkutFriendFactory.GetSelfFriends(startIndex, count);
        }

        /// <summary>
        /// Gets the friends of user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutPerson> GetFriendsOfUser(string userId, int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfFriends)
        {
            CheckForAuthorization();

            return OrkutFriendFactory.GetFriendsOfUser(userId, startIndex, count);
        }

        /// <summary>
        /// Sends the friend request.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public bool SendFriendRequest(string userId)
        {
            CheckForAuthorization();

            return OrkutFriendFactory.SendFriendRequest(userId);
        }

        /// <summary>
        /// Accepts the friend request.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public bool AcceptFriendRequest(string userId)
        {
            CheckForAuthorization();

            return OrkutFriendFactory.AcceptFriendRequest(userId);
        }

        /// <summary>
        /// Rejects the friend request.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public bool RejectFriendRequest(string userId)
        {
            CheckForAuthorization();

            return OrkutFriendFactory.RejectFriendRequest(userId);
        }

        /// <summary>
        /// Removes the friend request.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public bool RemoveFriendRequest(string userId)
        {
            CheckForAuthorization();

            return OrkutFriendFactory.RemoveFriendRequest(userId);
        }

        /// <summary>
        /// Gets the birthday notifications.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutBirthdayNotification> GetBirthdayNotifications(int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfBirthdayNotifications)
        {
            CheckForAuthorization();

            return OrkutFriendFactory.GetBirthdayNotifications(startIndex, count);
        }
        #endregion

        #region OrkutPhotoFactory
        /// <summary>
        /// Gets the self photos from album.
        /// </summary>
        /// <param name="albumId">The album id.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutPhoto> GetSelfPhotosFromAlbum(string albumId, int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfPictures)
        {
            CheckForAuthorization();

            return OrkutPhotoFactory.GetSelfPhotosFromAlbum(albumId, startIndex, count);
        }

        /// <summary>
        /// Gets the self photo from album.
        /// </summary>
        /// <param name="albumId">The album id.</param>
        /// <param name="photoId">The photo id.</param>
        /// <returns></returns>
        public OrkutData<OrkutPhoto> GetSelfPhotoFromAlbum(string albumId, string photoId)
        {
            CheckForAuthorization();

            return OrkutPhotoFactory.GetSelfPhotoFromAlbum(albumId, photoId);
        }

        /// <summary>
        /// Gets the photos from album.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="albumId">The album id.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutPhoto> GetPhotosFromAlbum(string userId, string albumId, int startIndex = 0, int count = OrkutLibraryConstants.DefaultNoOfPictures)
        {
            CheckForAuthorization();

            return OrkutPhotoFactory.GetPhotosFromAlbum(userId, albumId, startIndex, count);
        }

        /// <summary>
        /// Gets the photo from album.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="albumId">The album id.</param>
        /// <param name="photoId">The photo id.</param>
        /// <returns></returns>
        public OrkutData<OrkutPhoto> GetPhotoFromAlbum(string userId, string albumId, string photoId)
        {
            CheckForAuthorization();

            return OrkutPhotoFactory.GetPhotoFromAlbum(userId, albumId, photoId);
        }

        /// <summary>
        /// Deletes the photo.
        /// </summary>
        /// <param name="albumId">The album id.</param>
        /// <param name="photoId">The photo id.</param>
        /// <returns></returns>
        public bool DeletePhoto(string albumId, string photoId)
        {
            CheckForAuthorization();

            return OrkutPhotoFactory.DeletePhoto(albumId, photoId);
        }

        /// <summary>
        /// Updates the photo.
        /// </summary>
        /// <param name="photoToUpdate">The photo to update.</param>
        /// <returns></returns>
        public bool UpdatePhoto(OrkutPhoto photoToUpdate)
        {
            CheckForAuthorization();

            return OrkutPhotoFactory.UpdatePhoto(photoToUpdate);
        }
        #endregion

        #region OrkutScrapFactory
        /// <summary>
        /// Gets the self scraps.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutScrap> GetSelfScraps(int count = OrkutLibraryConstants.DefaultNoOfScraps)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.GetSelfScraps(count);
        }

        /// <summary>
        /// Gets the next set of self scraps.
        /// </summary>
        /// <param name="lastScrapId">The last scrap id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutScrap> GetNextSetOfSelfScraps(string lastScrapId, int count = OrkutLibraryConstants.DefaultNoOfScraps)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.GetNextSetOfSelfScraps(lastScrapId, count);
        }

        /// <summary>
        /// Gets the previous set of self scraps.
        /// </summary>
        /// <param name="firstScrapId">The first scrap id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutScrap> GetPreviousSetOfSelfScraps(string firstScrapId, int count = OrkutLibraryConstants.DefaultNoOfScraps)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.GetPreviousSetOfSelfScraps(firstScrapId, count);
        }

        /// <summary>
        /// Gets the scraps of user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutScrap> GetScrapsOfUser(string userId, int count = OrkutLibraryConstants.DefaultNoOfScraps)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.GetScrapsOfUser(userId, count);
        }

        /// <summary>
        /// Gets the next set of scraps of user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="lastScrapId">The last scrap id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutScrap> GetNextSetOfScrapsOfUser(string userId, string lastScrapId, int count = OrkutLibraryConstants.DefaultNoOfScraps)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.GetNextSetOfScrapsOfUser(userId, lastScrapId, count);
        }

        /// <summary>
        /// Gets the previous set of scraps of user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="firstScrapId">The first scrap id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutScrap> GetPreviousSetOfScrapsOfUser(string userId, string firstScrapId, int count = OrkutLibraryConstants.DefaultNoOfScraps)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.GetPreviousSetOfScrapsOfUser(userId, firstScrapId, count);
        }

        /// <summary>
        /// Deletes the self scrap.
        /// </summary>
        /// <param name="scrapToDelete">The scrap to delete.</param>
        /// <returns></returns>
        public bool DeleteSelfScrap(OrkutScrap scrapToDelete)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.DeleteSelfScrap(scrapToDelete);
        }

        /// <summary>
        /// Writes the scrap to user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="scrapText">The scrap text.</param>
        /// <returns></returns>
        public bool WriteScrapToUser(string userId, string scrapText)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.WriteScrapToUser(userId, scrapText);
        }

        /// <summary>
        /// Replies to scrap.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="scrapId">The scrap id.</param>
        /// <param name="scrapText">The scrap text.</param>
        /// <returns></returns>
        public bool ReplyToScrap(string userId, string scrapId, string scrapText)
        {
            CheckForAuthorization();

            return OrkutScrapFactory.ReplyToScrap(userId, scrapId, scrapText);
        }
        #endregion

        #region OrkutVideoFactory
        /// <summary>
        /// Gets the self videos.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutVideo> GetSelfVideos(int count = OrkutLibraryConstants.DefaultNoOfVideos)
        {
            CheckForAuthorization();

            return OrkutVideoFactory.GetSelfVideos(count);
        }

        /// <summary>
        /// Gets the next set of self videos.
        /// </summary>
        /// <param name="lastVideoId">The last video id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutVideo> GetNextSetOfSelfVideos(string lastVideoId, int count = OrkutLibraryConstants.DefaultNoOfVideos)
        {
            CheckForAuthorization();

            return OrkutVideoFactory.GetNextSetOfSelfVideos(lastVideoId, count);
        }

        /// <summary>
        /// Gets the previous set of self videos.
        /// </summary>
        /// <param name="firstVideoId">The first video id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutVideo> GetPreviousSetOfSelfVideos(string firstVideoId, int count = OrkutLibraryConstants.DefaultNoOfVideos)
        {
            CheckForAuthorization();

            return OrkutVideoFactory.GetPreviousSetOfSelfVideos(firstVideoId, count);
        }

        /// <summary>
        /// Gets the videos for user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutVideo> GetVideosForUser(string userId, int count = OrkutLibraryConstants.DefaultNoOfVideos)
        {
            CheckForAuthorization();

            return OrkutVideoFactory.GetVideosForUser(userId, count);
        }

        /// <summary>
        /// Gets the next set of videos for user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="lastVideoId">The last video id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutVideo> GetNextSetOfVideosForUser(string userId, string lastVideoId, int count = OrkutLibraryConstants.DefaultNoOfVideos)
        {
            CheckForAuthorization();

            return OrkutVideoFactory.GetNextSetOfVideosForUser(userId, lastVideoId, count);
        }

        /// <summary>
        /// Gets the previous set of videos for user.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="firstVideoId">The first video id.</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public OrkutData<OrkutVideo> GetPreviousSetOfVideosForUser(string userId, string firstVideoId, int count = OrkutLibraryConstants.DefaultNoOfVideos)
        {
            CheckForAuthorization();

            return OrkutVideoFactory.GetPreviousSetOfVideosForUser(userId, firstVideoId, count);
        }
        #endregion
    }
}
